﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi.Bill.Biz;
using WebApi.Models;

namespace WebApi.Controllers
{
    public class MeetingController : BaseController
    {

        #region 获取当天会议（大于等于当前时间）
        /// <summary>
        /// GetPageToList
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult<ResponseData> GetTodayMeetingPageToList([FromBody] dynamic param)
        {
            ResponseData res = new ResponseData();
            try
            {
                int recordCount = 0;
                int totalPage = 0;
                List<MeetingModel> data = BizBase.Get<BizMeeting>().GetPageList(param, ref recordCount, ref totalPage);
                if (data != null && data.Count > 0)
                {
                    res.ErrorCode = 0;
                    res.Message = "success";
                    res.DataList = new ModelData
                    {
                        DataList = data.Select(p=> new { SMeetingName = p.SMeetingName,SBookMan = p.SBookMan, STime = $"{p.TStart.ToString("HH:mm")}-{p.TEnd.ToString("HH:mm")}",SDay = p.TDay.ToString("yyyy-MM-dd") }),
                        TotalPage = totalPage,
                        RecordCount = recordCount
                    };
                }
                return new JsonResult(res);

            }
            catch (Exception ex)
            {
                return this.ControllerExHandler(res, "GetTodyMeetingPageToList", ex);
            }

        }
        #endregion

        #region 根据编码获取单条数据
        /// <summary>
        /// 根据编码获取单条数据
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<MeetingModel> Get(int code)
        {
            ResponseData res = new ResponseData();
            MeetingModel data = BizBase.Get<BizMeeting>().Get(code);
            try
            {
                if (data != null)
                {
                    res.ErrorCode = 0;
                    res.Message = "Success";
                    res.DataList = new ModelData
                    {
                        TotalPage = 0,
                        DataList = data
                    };
                }
                else
                {
                    res.ErrorCode = 1;
                    res.Message = "暂无数据";
                    res.DataList = null;
                }

                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                return this.ControllerExHandler(res, "Get", ex);
            }
        }
        #endregion

        #region 获取当前会议信息
        /// <summary>
        /// 获取当前会议信息
        /// </summary>
        /// <param name="sMeetingRoom">会议室名称</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<MeetingModel> GetCurrentMeeting(string sMeetingRoom)
        {
            ResponseData res = new ResponseData();
            try
            {
                dynamic data = BizBase.Get<BizMeeting>().GetCurrentMeeting(sMeetingRoom);
                res.ErrorCode = 0;
                res.Message = "Success";
                res.DataList = new ModelData
                {
                    TotalPage = 0,
                    DataList = data
                };
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                return this.ControllerExHandler(res, "GetCurrentMeeting", ex);
            }
        }
        #endregion

    }
}
